package roboGP;

/**
 * Rappresenta i nodi dell'albero che si traducono in istruzioni per il Robot. 
 * Ha un unico figlio opzionale.  
*/
public class ActionNode implements ITreeNode 
{
	private String _javaCode;
	private ITreeNode _child;
	private ITreeNode _parent;
	
	public ActionNode()
	{
		_javaCode = null;
		_child = null;
		_parent = null;
	}
	
	public ActionNode(String code, ITreeNode parent, ITreeNode child)
	{
		_javaCode = code;
		_child = child;
		_parent = parent;
	}
	
	public void setParent(ITreeNode node)
	{
		_parent = node;
	}
	
	public ITreeNode getParent()
	{
		return _parent;
	}
	
	public void setChild(ITreeNode node)
	{
		_child = node;
	}
	
	public ITreeNode getChild()
	{
		return _child;
	}
	
	public boolean hasChild()
	{
		return _child != null;
	}
	
	public void setJavaCode(String code)
	{
		_javaCode = code;
	}
	
	public String getJavaCode() 
	{
		return _javaCode;
	}
	
	public int getDepth()
	{
		return recGetDepth(this);
	}
	
	private int recGetDepth(ITreeNode node)
	{
		if (node.getParent() == null)
			return 0;
		
		return 1 + recGetDepth(node.getParent());
	}
	
}
